package sailhero

import (
	"fmt"
	"github.com/wsw188440873/ctrl-cali/types"
	"math"
)

func precision(modelId string, params map[string]interface{}, collectLen int) (map[string]float64, bool) {
	if _, ok := params["collect_data"]; !ok {
		return nil, false
	}
	if _, ok := types.Range[modelId]; !ok {
		return nil, false
	}
	avgParams := params["collect_data"].(map[string][]float64)
	avgMap := make(map[string]float64) //   标准气体测量平均值
	// 计算每一次的平均值
	for key, values := range avgParams {
		sum := float64(0)
		length := 0
		for _, v := range values {
			length++
			sum += v
		}
		//计算平均值.
		avgMap[key] = sum / float64(length)
	}
	fmt.Println("-----测试测试:-------", avgMap)
	// 计算精密度.
	precisionMap := make(map[string]float64)
	for key, value := range avgParams {
		sum := float64(0)
		avg := avgMap[key]
		for _, v := range value {
			sum += math.Pow(v-avg, 2)
		}
		P := sum / float64(len(value)-1)
		precisionMap[key] = math.Sqrt(P)
	}
	fmt.Println("测试测试:", precisionMap)
	return precisionMap, true
}
